package com.youbug.common.util;

import com.youbug.system.entity.Menu;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class MenuUtils {

    public static List<Menu> makeMenuTree(List<Menu> list, Long pid) {

        List<Menu> nodes = new ArrayList<>();

        Iterator<Menu> iterator = list.iterator();

        while(iterator.hasNext()){

            Menu temp = iterator.next();

            if(temp.getParentId().equals(pid)){

                List<Menu> menuTemps = makeMenuTree(list, temp.getId());

                temp.setChildren(menuTemps);

                nodes.add(temp);
            }
        }

        return nodes;
    }

}
